import myRequest from '../request.js'

import dicts from '@/config/dicts.js'


// 获取发票分页信息
export const getInvoiceList = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt`, 'get', val).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 本月是否可申请发票  
export const getApplicableInvoiceNum = () => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt/invoicing/times`, 'get').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 获取发票详情  
export const getInvoiceDetails = (id) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt/${id}`, 'get').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 可开具发票的订单列表    
export const getIssueInvoicesList = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/order/order/invoicable/orders`, 'get', val).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 申请开票发票
export const applyInvoicing = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt`, 'post', val, { 'Content-type': 'application/json' }).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 申请冲红   
export const applicationFlushRed = (id) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt/${id}/reissuing`, 'put').then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}
// 分享 发票    
export const shareInvoice = (invoiceId, params) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/trade/receipt/invoice/${invoiceId}/wechat`, 'get', params).then(res => {
      resolve(res)
    }).catch((err) => { reject(err) })
  })
}

